<?php

class Admin_Search_City extends Controller
{
	var $data=array();
	
	public function __construct()
	{
		parent::Controller();
        include("password_protect.php");
		$this->load->model('Admin_Input_Model');
		$this->load->model('Admin_Quotation_Model');

		$this->data['warning']="";
		$this->data['success']="";
		$this->data['search']="";
		$this->data['search_province']="";


	}
	
	function index()
	{
		if($this->input->post('search_city'))
		{
			$this->data['search']=trim($this->input->post('search'));
			
			$this->search_city($this->data['search']);
		}

		else if($this->input->post('delete_city'))
		{
			$this->delete_city();
			
//			$this->data['search_city_list']=$this->Admin_Input_Model->list_search_city($this->data['search']);
		}
		else
			$this->load->view("admin_search_city",$this->data);

	}
	
	function search_city($city)
	{
//		echo "X | ";
		
		$this->data['search_city_list']=$this->Admin_Input_Model->list_search_city($city);
		
		if(count($this->data['search_city_list'])==0)
		{
			$this->data['warning']="No city with name \"".$city."\" was found.";
		}

		$this->load->view("admin_search_city",$this->data);

	}
	
	function delete_city($id, $city_name)
	{
		if($id>=0)
		{	
			$this->Admin_Input_Model->delete_city($id);
			$this->data['success']="City \"".$city_name."\" has been deleted.";
		}
		else
			echo $id;
			
		$this->data['search']=trim($this->input->post('search'));
		$this->search_city($this->data['search']);


	}
}
